﻿using System;

namespace WWB.SitePointPrivateMessages.Core.Model.Messages
{
    public class ForumUser : IEquatable<ForumUser>, IComparable<ForumUser>
    {
        public const int UnknownId = -1;
        public int Id { get; set;}
        public string Name { get; set;}

        public ForumUser()
        {
            Id = UnknownId;
            Name = "ANONOMOUS";
        }

        public bool Equals(ForumUser other)
        {
            if (other == null)
            {
                throw new ArgumentNullException("other");
            }
            return other.GetHashCode() == this.GetHashCode();
        }

        public int CompareTo(ForumUser other)
        {
            if (other == null)
            {
                throw new ArgumentNullException("other");
            }
            return this.Name.CompareTo(other.Name);
        }

        public override int GetHashCode()
        {
            return (Id + Name).GetHashCode();
        }

        public override string ToString()
        {
            return string.Format("{0} [{1}]", Name, Id > 0 ? Id.ToString() : "??");
        }

        public override bool Equals(object obj)
        {
            var that = obj as ForumUser;
            return Equals(that);
        }

        public static bool operator == (ForumUser a, ForumUser b)
        {
            if (ReferenceEquals(a, b))
            {
                return true;
            }
            if (((object)a == null) || ((object)b == null))
            {
                return false;
            }
            return a.Equals(b);
        }

        public static bool operator != (ForumUser a, ForumUser b)
        {
            return !(a == b);
        }
    }
}
